package t2h.listsong;

import t2h.valueobjects.SongVO;

import com.sun.lwuit.Container;
import com.sun.lwuit.Form;
import com.sun.lwuit.List;
import com.sun.lwuit.events.ActionEvent;
import com.sun.lwuit.events.ActionListener;
import com.sun.lwuit.list.DefaultListModel;
import com.sun.lwuit.list.ListCellRenderer;
import com.sun.lwuit.list.ListModel;

public class TwoRowListView extends ListView {

    ListModel model = new DefaultListModel();
    
    public TwoRowListView() {
        //setTitle("Two rows in item");

        // Create a list model
        for (int i = 0; i < MAX_ITEMS; i++) {
        	//Add thong tin bai hat o day
            String id = LIST_ITEM_TEXT + (i + 1);
            String name = "Name of " + (i + 1) ;

            SongVO item = new SongVO(id, name, "Lyric of " + id); 
            model.addItem(item);
        }

        // Create a list based on the model
        list = new List(model);
        
       

        // Create and set thelist renderer
        ListCellRenderer renderer = new TwoRowListCellRenderer();
        list.setRenderer(renderer);

        // Add ActionListener for the list
        list.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        showSelectedDialog((SongVO) list.getSelectedItem());
                    }
                });

        addComponent(list);
        layoutContainer();
    }
    
    public TwoRowListView(ListModel listmodel) {
        //setTitle("Two rows in item");

        // Create a list model
        /*for (int i = 0; i < MAX_ITEMS; i++) {
        	//Add thong tin bai hat o day
            String id = LIST_ITEM_TEXT + (i + 1);
            String name = "Name of " + (i + 1) ;

            SongVO item = new SongVO(id, name, "Lyric of " + id); 
            model.addItem(item);
        }*/
    	
    	model = listmodel;

        // Create a list based on the model
        list = new List(model);

        // Create and set thelist renderer
        ListCellRenderer renderer = new TwoRowListCellRenderer();
        list.setRenderer(renderer);

        // Add ActionListener for the list
        list.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        showSelectedDialog((SongVO) list.getSelectedItem());
                    }
                });

        addComponent(list);
        layoutContainer();
    }
    
    public TwoRowListView(ListModel listmodel, final Form f) {
        //setTitle("Two rows in item");

        // Create a list model
        for (int i = 0; i < MAX_ITEMS; i++) {
        	//Add thong tin bai hat o day
            String id = LIST_ITEM_TEXT + (i + 1);
            String name = "Name of " + (i + 1) ;

            SongVO item = new SongVO(id, name, "Lyric of " + id); 
            model.addItem(item);
        }
    	
    	model = listmodel;

        // Create a list based on the model
        list = new List(model);

        // Create and set thelist renderer
        ListCellRenderer renderer = new TwoRowListCellRenderer();
        list.setRenderer(renderer);

        // Add ActionListener for the list
        list.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        showSelectedDialog((SongVO) list.getSelectedItem(), f);
                    }
                });

        addComponent(list);
        layoutContainer();
    }
    
    public void setNewModel(ListModel listmodel){
    	list.setModel(listmodel);
    	layoutContainer();
    }
    
    /*public void addSelectedDialog(final Form f){
    	list.addActionListener(
                new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        showSelectedDialog((SongVO) list.getSelectedItem(), f);
                    }
                });
    }*/
}
